package com.xc.freeapp.service.impl;


import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xc.freeapp.dao.VaccineDao;
import com.xc.freeapp.dao.dataSource.DBContextHolder;
import com.xc.freeapp.entity.Vaccine;
import com.xc.freeapp.exception.BaseException;
import com.xc.freeapp.service.VaccineService;
import com.xc.freeapp.util.DateUtils;

@Service
public class VaccineServiceImpl implements VaccineService {
	private Logger log = Logger.getLogger(this.getClass());
	@Autowired
	VaccineDao vaccineDao;
	public List<Vaccine> getVaccineList(Map<String,String> map) throws BaseException{
		DBContextHolder.switchDataSourceRW();//切换数据源
		List<Vaccine> vaccines=null;
		try {
			int userid= Integer.parseInt(map.get("userid"));
			int vaccineperid= Integer.parseInt(map.get("vaccineperid"));
			vaccines =vaccineDao.selectByVaccineperid(userid, vaccineperid);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error("更新疫苗信息出错"+e.getMessage());
			throw new BaseException("999", "更新疫苗信息到数据库出错");
		}
		return vaccines;

	}
	public Boolean  saveVaccine (Vaccine vaccine) throws Exception{
		DBContextHolder.switchDataSourceRW();//切换数据源
		int saveCount =0;
		try {

			vaccineDao.insert(vaccine);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			log.error("更新疫苗信息出错"+e.getMessage());
			throw new BaseException("999", "更新疫苗信息到数据库出错");
		}
		if(saveCount==1){
			return true;
		}else{
			return false;
		}
		
	}
	
}
